﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EFTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            EFTestContext context = new EFTestContext();
            var gg = context.Order.FirstOrDefault();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            EFTestContext context = new EFTestContext();
            context.Database.Log = Console.WriteLine;
            //context.Configuration.LazyLoadingEnabled = true;
            //context.Configuration.AutoDetectChangesEnabled = false;
            //context.Configuration.UseDatabaseNullSemantics = true;
            var id = new Guid("6C0823A1-60A7-442A-9CE1-7B795F196807");
            //var r = context.Order.Find(id);
            var r2 = context.Order_2.Find(id);

            EFTestContext context2 = new EFTestContext();
            var r2_2 = context2.Order_2.Find(id);

            

            // 备注:
            //     The format of the log text can be changed by creating a new formatter that
            //     derives from System.Data.Entity.Infrastructure.Interception.DatabaseLogFormatter
            //     and setting it with System.Data.Entity.DbConfiguration
            //.SetDatabaseLogFormatter(System.Func<System.Data.Entity.DbContext,System.Action<System.String>,
            //System.Data.Entity.Infrastructure.Interception.DatabaseLogFormatter>).
            //      For more low-level control over logging/interception 
            //see System.Data.Entity.Infrastructure.Interception.IDbCommandInterceptor
            //     and System.Data.Entity.Infrastructure.Interception.DbInterception.

            //System.Data.Entity.DbConfiguration.SetConfiguration(

            r2._2_GGG = "dfgdfgdfgdfgdfg";

            //r2_2._2_GGG = "111111111111111111111111111111111111";


            //context.ChangeTracker.DetectChanges();

            //var gg = context.Order_2.Where(p => p._2_GGG == null).ToList();
            var gg = context.Order_2.Where(p => p._2_GGG == p.RowV).ToList();
            context.SaveChanges();
            //context2.SaveChanges();




        }
    }

    public static class xx
    {
        public static string ToJson(this object obj)
        {

            return Newtonsoft.Json.JsonConvert.SerializeObject(obj,
                new Newtonsoft.Json.JsonSerializerSettings()
                {
                    ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
                });
        }
    }
}
